package com.lx.constant.others.limit;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * 基础分页对象
 *
 * @author lx
 * @create 2022/9/14 15:19
 **/
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BasePage implements Serializable {
    /**
     * 当前页数
     */
    private Integer currentPage;

    /**
     * 分页大小
     */
    private Integer pageSize;

    public Integer getCurrentPage() {
        return (currentPage == null || currentPage < 1) ? 1 : currentPage;
    }

    public Integer getPageSize() {
        return pageSize == null || pageSize < 0 ? 20 : pageSize;
    }

    /**
     * 获取当前页对应的真实下标值.
     *
     * @return
     */
    public Integer getCurrentSize() {
        return (getCurrentPage() - 1) * getPageSize();
    }
}
